DevOPs
Published:
DevOPs
Deploy Environment
- Deploy Scale
- AWS
- GCP
- Azure
- Local
- Differnet Deploy Region
- Asia
- US
- Europe The Deploy configuration status is such complex e.g. DNS settings
- Dev Testing Environments Production - Staging - QA - DEV
- Codebase One Codebase tracked in revision control, many deploys Codebase –> Deploys - Production - Staging - Developer1 - Developer2
Dockerfile in differents ENV using docker run
to build the same ENV of docker build
.
- Dependencies Explicitly declare and isolate dependencies Dockerfile have install application and progress Docker image –> Quota / Commit
# 安裝 bcmath 與 redis
RUN docker-php-ext-install bcmath
RUN pecl install redis
RUN docker-php-ext-enable redis
# 安裝程式依賴套件
COPY composer.* ./
RUN composer install --no-dev --no-scripts && composer clear-cache
FROM php:7.3
# 全域設定
WORKDIR /source
# 安裝環境、安裝工具
RUN curl -sS https://getcomposer.org/installer | php && mv composer.phar /usr/local/bin/composer
RUN apt update && apt install unzip && apt clean && rm -rf /var/lib/apt/lists/* //&& apt clean && rm -rf /var/lib/apt/lists/*
# 安裝 bcmath 與 redis
RUN docker-php-ext-install bcmath
RUN pecl install redis
RUN docker-php-ext-enable redis
# 加速套件下載的套件
RUN composer global require hirak/prestissimo && composer clear-cache //&& composer clear-cache
# 安裝程式依賴套件
COPY composer.* ./
RUN composer install --no-dev --no-scripts && composer clear-cache
//&& composer clear-cache, Composer 加上 --no-dev 參數即可排除開發階段安裝的套件
# 複製程式碼
COPY . .
RUN composer run post-autoload-dump
CMD ["php", "artisan", "serve", "--host", "0.0.0.0"]
Like apt
和 composer global require
download file will have cache and commit
into image. No need to save those files. Dockerfile into Docker image concept: one command one commit. how many commit will occupy have many quota.
- Config Store config in the environment
- IV. Backing Services Setting, like DB / Redis and so on.
- Third party services credentials. Like AWS.
- Application at different environment will have special setting, like domain. Different ENV setting the difference is such big. so the same sourcecode is well operating.
- Secure, like credentials won’t have the issues to outsourcing
- If the setting put in the sourcefile, then if you want to edit the file. you have to edit sourcecode. but it is put in the env then you only need to modigy the Env.
- Backing Services
- Build, Release, Run
- Processes
- Port Binding
- Concurrency
- Disposability
- Docker Concept ENTRYPOINT / CMD
ENTRYPOINT ["curl"] CMD ["http://dummy-url.com/"]
container start will execute
curl http://dummy-url.com/
ENTRYPOINT
- _shell_form
- _exec_form
Shell Form ENTRYPOINT command param1 param2
/bin/sh-c
execute –> so previous practice is /bin/sh-c curl
ENTRYPOINT curl${url}
env variable must define the url
varible and you will get the vaule.
Exec Form ENTRYPOINT ["execute","param1","parama2"]
won’t use /bin/sh -c
to execute so it can’t read the ENV variable vaule. but you can use the manual way to specific the execute environment. Like /bin/sh -c
ENTRYPOINT ["/bin/sh","-c","echo $HOME"]
Executing commands Using CMD V.S. ENTRYPOINT Dockerfile : Installs http-tools an starts the ab (apache benchmark) utility using CMD and ENTRYPOINT.
CMD
Using CMD:
FROM centos:7
MAINTAINER magicansk
RUN yum -y update && \
CMD
ENTRYPOINT
Using ENTRYPOINT:
FROM centos:7
MAINTAINER magicansk
RUN
ENTRYPOINT
JSON 大多用於資料傳輸,YAML 大多用於組態設定